from django.db import models
from users.models import User

class Columns(models.Model):
    """
    专栏类别模型类
    """
    name = models.CharField(max_length=32, verbose_name="专栏名", unique=True)
    weight = models.IntegerField(verbose_name="权重", default=1, unique=True, editable=True)
    is_active = models.BooleanField(verbose_name="是否显示", default=True)
    create_time = models.DateTimeField(verbose_name="创建时间")

    class Meta:
        db_table = 'tb_columns'
        verbose_name = "专栏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Headlines(models.Model):
    """
    头条详情类
    """
    column = models.ForeignKey(Columns, verbose_name='专栏id')
    title = models.CharField(max_length=32, verbose_name="主标题", unique=True)
    user = models.ForeignKey(User, verbose_name="发布人")
    create_time = models.DateTimeField(verbose_name="创建时间")
    default_image = models.ImageField(verbose_name='图片地址', null=True, blank=True)
    content = models.TextField(verbose_name='内容', )
    is_active = models.BooleanField(verbose_name="是否显示", default=True)
    is_delete = models.BooleanField(verbose_name="是否删除", default=False)
    clicks = models.IntegerField(verbose_name='点击量', default=0)
    live_count = models.IntegerField(verbose_name='收藏量', default=0)
    is_vip = models.BooleanField(verbose_name='精品头条',default=False)

    class Meta:
        db_table = 'tb_headline'
        verbose_name = "头条"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title

class HeadlineComments(models.Model):
    """
    头条详情评论类
    """
    user = models.ForeignKey(User, verbose_name='用户id')
    headline = models.ForeignKey(Headlines, verbose_name='头条id')
    create_time = models.DateTimeField(verbose_name='创建时间')
    comment_content = models.CharField(max_length=256, verbose_name='评论内容')


    class Meta:
        db_table = 'tb_headline_comment'
        verbose_name = "头条详情评论"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.comment_content

class OtherComments(models.Model):
    """
    楼中楼评论模型类
    """
    user = models.ForeignKey(User, verbose_name='用户id')
    headline_comment = models.ForeignKey(HeadlineComments, verbose_name='头条主评论父id')
    comment_content = models.CharField(max_length=256, verbose_name='评论内容')
    create_time = models.DateTimeField(verbose_name='创建时间')
    parent = models.ForeignKey('self',verbose_name='要回复用户', null=True, blank=True)

    class Meta:
        db_table = 'tb_other_comment'
        verbose_name = "楼中楼评论表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.comment_content
